/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaShowAlocation.java
 *
 * Created on Dec 14, 2011, 7:43:53 PM
 */
package com.googlecode.view;

import com.googlecode.services.Facade;
import com.googlecode.entity.Turma;
import java.util.List;

/**
 *
 * @author italo
 */
public class TelaShowAlocation extends javax.swing.JFrame {

    /** Creates new form TelaShowAlocation */
    public TelaShowAlocation() {
        this.f = Facade.getInstance();
        initComponents();
        this.labelAlocacaoNaoPermitida.setVisible(false);
        preencherHorarios();
        this.jInternalFrame1.setTitle("ALOCAR TURMA");
        this.boxTurma.addItem("ESA1");
        this.boxTurma.addItem("POO");
        this.boxTurma.addItem("SO");
        this.boxTurma.addItem("REDES");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tableAlocation = new javax.swing.JTable();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        boxTurma = new javax.swing.JComboBox();
        boxHorarios = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        buttonAlocar = new javax.swing.JButton();
        boxSemana = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        labelAlocacaoNaoPermitida = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tableAlocation.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "HORÁRIOS", "SEGUNDA", "TERÇA", "QUARTA", "QUINTA", "SEXTA"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableAlocation.setRowHeight(60);
        jScrollPane1.setViewportView(tableAlocation);

        jInternalFrame1.setVisible(true);

        boxHorarios.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "08:00 | 10:00", "10:00 | 12:00", "13:00 | 15:00", "15:00 | 17:00" }));

        jLabel2.setText("Horários:");

        jLabel1.setText("Turmas:");

        jLabel3.setText("Dia da semana:");

        buttonAlocar.setText("Alocar");
        buttonAlocar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAlocarActionPerformed(evt);
            }
        });

        boxSemana.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda", "Terça", "Quarta", "Quinta", "Sexta" }));

        jButton1.setText("Voltar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        labelAlocacaoNaoPermitida.setFont(new java.awt.Font("Ubuntu", 1, 15));
        labelAlocacaoNaoPermitida.setForeground(new java.awt.Color(243, 12, 12));
        labelAlocacaoNaoPermitida.setText("Alocação não permitida, horário já alocado!");

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(boxTurma, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(labelAlocacaoNaoPermitida))
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(boxHorarios, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(boxSemana, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(buttonAlocar, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)))
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 370, Short.MAX_VALUE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(labelAlocacaoNaoPermitida))
                .addGap(4, 4, 4)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(boxSemana, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boxHorarios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)
                        .addComponent(jLabel1))
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(buttonAlocar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(boxTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(97, 97, 97))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1262, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(121, 121, 121)
                .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(696, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonAlocarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAlocarActionPerformed
        this.labelAlocacaoNaoPermitida.setVisible(false);
        int linha = converterHora((String) this.boxHorarios.getSelectedItem());
        int coluna = converterDia((String) this.boxSemana.getSelectedItem());
        
        if (this.tableAlocation.getValueAt(linha, coluna) == null){
            this.tableAlocation.setValueAt(this.boxTurma.getSelectedItem(), linha, coluna);
        }else{
            this.labelAlocacaoNaoPermitida.setVisible(true);
        }
    }//GEN-LAST:event_buttonAlocarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void permission(Turma t){
        
    }
    
    private int converterHora(String hora){
        int aux = 0;
        
        if (hora.charAt(1) == '8'){
            aux = 0;
        }
        if (hora.charAt(1) == '0'){
            aux = 1;
        }
        if (hora.charAt(1) == '3'){
            aux = 3;
        }
        if (hora.charAt(1) == '5'){
            aux = 4;
        }
        return aux;
    }
    
    private int converterDia(String dia){
        int aux = 0;
        
        if (dia.startsWith("Seg")){
            aux = 1;
        }
        if (dia.startsWith("Ter")){
            aux = 2;
        }
        if (dia.startsWith("Qua")){
            aux = 3;
        }
        if (dia.startsWith("Qui")){
            aux = 4;
        }
        if (dia.startsWith("Sex")){
            aux = 5;
        }
        return aux;
    
    }
    
    
    private void preencherHorarios(){
        this.tableAlocation.setValueAt("08:00 | 10:00", 0, 0);
        this.tableAlocation.setValueAt("10:00 | 12:00", 1, 0);
        this.tableAlocation.setValueAt("13:00 | 15:00", 3, 0);
        this.tableAlocation.setValueAt("15:00 | 17:00", 4, 0);
    }
    
    private void preencherBoxTurmas(List<Turma>turmas){
        for(Turma t : turmas){
            this.boxTurma.addItem(t.getNome());
        }
        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaShowAlocation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaShowAlocation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaShowAlocation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaShowAlocation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaShowAlocation().setVisible(true);
            }
        });
    }
    Facade f;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxHorarios;
    private javax.swing.JComboBox boxSemana;
    private javax.swing.JComboBox boxTurma;
    private javax.swing.JButton buttonAlocar;
    private javax.swing.JButton jButton1;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelAlocacaoNaoPermitida;
    private javax.swing.JTable tableAlocation;
    // End of variables declaration//GEN-END:variables
}
